## Plotkin upper bound

from PyM import *

def ub_plotkin(n,d,q=2):
    b = (q-1)/q
    if d > b*n:
        if q==2:
            if d % 2:
                n += 1; d += 1
            return 2 * int(floor(d/(2*d-n)))
        else:
            return int(floor(d/(d-b*n)))
    m = (b*n-d)/b
    if m == int(m):
        m +=1
    else:
        m = int(ceil(m))
    return int(q**m * ub_plotkin(n-m,d,q))
                
show(ub_plotkin(13,5))
show(ub_plotkin(32,16))

show([ub_plotkin(n,3) for n in range(5,9)])

show([ub_plotkin(n,5) for n in range(5,13)])

show([ub_plotkin(n,7) for n in range(7,17)])